#!usr/bin/env python  
# -*- coding:utf-8 _*-
""" 
@author:robot
@file: tpf_logcollector.py 
@version:
@time: 2022/05/17 
"""
from TapClientCore.T05_TM_feature.v2.TMF08_logcollector.tmf_logcolllector import TMFLogCollector
from TapUtil.decorator.some_useful import timeout, more_time_check
from TapUtil.logfunc.logger import logger


class TPFLogCollector(TMFLogCollector):

    # 等待共享挖掘任务存在
    @timeout('exist', 12)
    def wait_logcollector_create(self, connection_name):
        if self.get_logcollector_by_connection_name(connection_name):
            logger.info('共享挖掘任务存在')
            return 'exist'
        else:
            return 'not exist'

    # 共享挖掘任务 一定时间任务状态正常
    @more_time_check('running', 5)
    def logcollector_status_running(self, connection_name):
        logger.info('共享挖掘任务状态判断')
        result = self.get_logcollector_by_connection_name(connection_name)
        return result.get('status')

    # 共享挖掘任务 一定时间任务状态正常
    @timeout(['edit', 'running'], 24)
    def logcollector_status_ready(self, connection_name):
        self.renew_logcollector_by_name(connection_name)
        result = self.get_logcollector_by_connection_name(connection_name)
        return result.get('status')

    # 共享挖掘中调度任务 一定时间状态正常
    @more_time_check('schedule_failed', 5)
    def logminer_status_schedule_failed(self, connection_name, task_name):
        logger.info('共享挖掘任务状态判断')
        result = self.get_logminer_by_connection_name_and_task_name(
            connection_name,
            task_name
        )
        return result.get('status')

    @more_time_check('edit', 5)
    def logminer_status_edit(self, connection_name, task_name):
        logger.info('共享挖掘任务状态判断')
        result = self.get_logminer_by_connection_name_and_task_name(
            connection_name,
            task_name
        )
        return result.get('status')

    @more_time_check('running', 5)
    def logminer_status_running(self, connection_name, task_name):
        logger.info('共享挖掘子任务调度状态判断')
        result = self.get_logminer_by_connection_name_and_task_name(
            connection_name,
            task_name
        )
        return result.get('status')
    # task shareCdcEnable
